package com.shengqi.xinnongren.work.ui.goods.activities;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.TextView;

import com.shengqi.xinnongren.R;
import com.shengqi.xinnongren.common.base.BaseMvpActivity;
import com.shengqi.xinnongren.common.utils.ToastHelper;
import com.shengqi.xinnongren.work.common.MyWebViewActivity;
import com.shengqi.xinnongren.work.ui.goods.model.PayResultBean;
import com.shengqi.xinnongren.work.ui.goods.presenter.PayResultPresenter;
import com.shengqi.xinnongren.work.ui.goods.view.PayResultView;
import com.shengqi.xinnongren.work.ui.home.activities.MainActivity;
import com.shengqi.xinnongren.work.ui.user.activities.MyOrderListActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class PayResultActivity extends BaseMvpActivity<PayResultView, PayResultPresenter> implements PayResultView {

    private static final String EXTRA_CONTENT = "orderId";

    @BindView(R.id.tv_price)
    TextView mTvPrice;

    private String orderId;

    private String protocol;

    public static void start(Context context, String orderId) {
        Intent intent = new Intent(context, PayResultActivity.class);
        intent.putExtra(EXTRA_CONTENT, orderId);
        context.startActivity(intent);
    }

    @Override
    protected int setContentLayoutRes() {
        return R.layout.activity_pay_result;
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        if (intent != null) {
            orderId = intent.getStringExtra(EXTRA_CONTENT);
        }
    }

    @Override
    protected void initData() {
//        mPresenter.getPayRes(orderId);
    }


    @OnClick(R.id.ll_order)
    void order() {
        startActivity(new Intent(this, MyOrderListActivity.class));
        finish();
    }

    @OnClick(R.id.ll_return)
    void goHome() {
        gotoMain();
    }

    private void gotoMain() {
        closeAllActivities();
        startActivity(new Intent(this, MainActivity.class));
    }

    @Override
    protected PayResultPresenter createPresenter() {
        return new PayResultPresenter();
    }

    @Override
    public void showLoadingView() {

    }

    @Override
    public void hideLoadingView() {

    }

    @Override
    public void onNetworkError() {

    }


    @Override
    public void showPayRes(PayResultBean data) {
        mTvPrice.setText(String.format("￥%s", data.getMoney()));
        protocol = data.getProtocol();
    }

    @Override
    public void showRequestFailed(String message) {
        ToastHelper.getInstance(this).showWarn(message);
    }
}
